﻿CreateGoogle(160,600,null,null,null,null,null,null,null,null);
var gPageIndex = 1;
var gLastCount = 15;
var SortListTag = 0;
function pageLoad(sender, args) 
{
    switch(ShowUserType)
    {     
        case 1:
            if(typeof(userPage) != "undefined")
            {
                RendPageNavigator(userPage,"divPage","GetPageMembers");                
            }            
            break;
        case 2:            
            InitDataMembers(2,1);            
            break;
    }    
}
function HideOpMesage()
{
    var obj = $get("OPMessgeID");
    if(obj!=null)
    {
        obj.style.display = "none";
    }
}
//当前数据类型 
function SortList(type)
{
    if(SortListTag==1) return;
    SortListTag = 1;	
    showProgressBar(true);    
	switch(type)
	{
		case 10:
			$get("FriendTags").className = "selATags first";
			$get("ReceTags").className = "unselATags";
			$get("SendTags").className = "unselATags";
			break;
		case 2:
			$get("FriendTags").className = "unselATags first";
			$get("ReceTags").className = "selATags";
			$get("SendTags").className = "unselATags";
			break;
		case 3:
			$get("FriendTags").className = "unselATags first";
			$get("ReceTags").className = "unselATags";
			$get("SendTags").className = "selATags";
			break;
	}    
    if(type!=10)
    {
       ShowUserType=type;
       if(HaveOrNoF!=0)
       {
            $get("QuestList").style.display="none";
       }
    }
    else{
       FriendCount!=0 ? ShowUserType=1:ShowUserType=0;
       if(HaveOrNoF!=0)
       {
            $get("QuestList").style.display="";
       }
    }
    InitDataMembers(ShowUserType,1);
}
//初始数据
function onsuccMembers(result)
{    
    if(HaveOrNoF==0)
    {
        RendMemberList(result[1],"NoFriends");
    }
    else
    {
        RendMemberList(result[1],"ContactFriends");
    }
    RendPageNavigator(result[0],"divPage","GetPageMembers");
    showProgressBar(false);
    SortListTag = 0;
}
//获取数据（当前显示的类型0结交新朋友信息，1我的好友信息，2我收到请求的会员信息，3我发送请求的会员信息）
function InitDataMembers(userType,pageIndex)
{
    WebServices.User.Contacts.GetContactMembers(Memberno,userType,pageIndex,10,onsuccMembers);
}
//获取页面数据（页索引）
function GetPageMembers(pageIndex)
{
	showProgressBar(true);
    gPageIndex = pageIndex;
    InitDataMembers(ShowUserType,pageIndex);
}
//替换数据
function RendMemberList(list,divID)
{

    HideOpMesage();
    var domDiv =$get(divID);    
    if(domDiv!=null)
    {  
        if(Sys.UI.DomElement.containsCssClass(domDiv, "DisplayNone"))
        {
            Sys.UI.DomElement.removeCssClass(domDiv, "DisplayNone");
        }   
        if(ShowUserType==0)
        {
                  
            if($get("NoFriendsItem")==null) return;                   
            var item= $get("NoFriendsItem").innerHTML;
            var listBuilder = new Sys.StringBuilder();
            gLastCount = list.length;            
            for (var index = 0; index < gLastCount; index++) 
            {              
                var obj = list[index];                     
                var tmp = item.replace(/\$Avatar\$/gi,"<img src=\""+(obj.Avatar==""?"/Images/No_pic.gif":obj.Avatar)+"\"/>").replace(/\$MemberNo\$/gi,obj.MemberNo).replace(/\$NickName\$/gi,obj.Nickname);
                tmp = tmp.replace(/\$Online\$/gi,obj.Online?"<img src='/Images/online.gif' />":"<img src='/Images/offline.gif' />");
                tmp = tmp.replace(/\$from\$/gi,C0102.replace("{0}",GetLanguageLabel("jselCountry",obj.Nationality)));
                tmp = tmp.replace(/\$learnNo\$/gi,C0103.replace("{0}",GetLanguageLabel("selLang",obj.TargetLanguage)));
                tmp = tmp.replace(/\$speakNo\$/gi,C0104.replace("{0}",GetLanguageLabel("selLang",obj.MotherTongue))).replace(/\$AddContats\$/gi,"onclick=\"$AddFriends$('"+obj.MemberNo+"')\"");
                listBuilder.append(tmp);
            }
            var sTemp = listBuilder.toString();
            domDiv.innerHTML = sTemp;             
        }
        else
        {
            if($get("ContactsItem")==null) return;        
            var item= $get("ContactsItem").innerHTML;
            var listBuilder = new Sys.StringBuilder();
            gLastCount=list.length;
            for (var index = 0; index < gLastCount; index++) 
            {              
                var obj = list[index];                     
                var tmp = item.replace(/\$Avatar\$/gi,"<img src=\""+(obj.Avatar==""?"/Images/No_pic.gif":obj.Avatar)+"\"/>").replace(/\$MemberNo\$/gi,obj.MemberNo).replace(/\$NickName\$/gi,obj.Nickname);
                tmp = tmp.replace(/\$Age\$/gi,(obj.Age != "" &&obj.IsShowBod)? obj.Age+" ":"" ).replace(/\$Nationality\$/gi,GetLanguageLabel("jselCountry",obj.Nationality)).replace(/\$Country\$/gi," "+GetLanguageLabel("jselCountry",obj.Country)).replace(/\$City\$/gi,obj.City!=""? obj.City:"");
                tmp = tmp.replace(/\$MotherTongue\$/gi,GetLanguageLabel("selLang",obj.MotherTongue)+"<img src=\"/Images/Level5.gif\"/>");
                tmp = tmp.replace(/\$TargetLanguage\$/gi,GetLanguageLabel("selLang",obj.TargetLanguage)+"<img src=\"/Images/Level"+obj.TargetLanguageLevel+".gif\"/>");
                tmp = tmp.replace(/\$MotherTongue2\$/gi,obj.MotherTongue2 != "" ? ", "+GetLanguageLabel("selLang",obj.MotherTongue2)+"<img src=\"/Images/Level"+obj.MotherTongue2Level+".gif\"/>" : "");
                tmp = tmp.replace(/\$MotherTongue3\$/gi,obj.MotherTongue3 != "" ? ", "+GetLanguageLabel("selLang",obj.MotherTongue3)+"<img src=\"/Images/Level"+obj.MotherTongue3Level+".gif\"/>" : "");
                tmp = tmp.replace(/\$MotherTongue4\$/gi,obj.MotherTongue4 != "" ? ", "+GetLanguageLabel("selLang",obj.MotherTongue4)+"<img src=\"/Images/Level"+obj.MotherTongue4Level+".gif\"/>" : "");
                tmp = tmp.replace(/\$TargetLanguage2\$/gi,obj.TargetLanguage2 != "" ? ", "+GetLanguageLabel("selLang",obj.TargetLanguage2)+"<img src=\"/Images/Level"+obj.TargetLanguage2Level+".gif\"/>" : "");
                tmp = tmp.replace(/\$TargetLanguage3\$/gi,obj.TargetLanguage3 != "" ? ", "+GetLanguageLabel("selLang",obj.TargetLanguage3)+"<img src=\"/Images/Level"+obj.TargetLanguage3Level+".gif\"/>" : "");
                tmp = tmp.replace(/\$TargetLanguage4\$/gi,obj.TargetLanguage4 != "" ? ", "+GetLanguageLabel("selLang",obj.TargetLanguage4)+"<img src=\"/Images/Level"+obj.TargetLanguage4Level+".gif\"/>" : "");                
                tmp = tmp.replace(/\$Avatar_title\$/gi,obj.Avatar_title == "" ? "" : "<div class='thoughtbox'><div><div><div><div>"+obj.Avatar_title+"</div></div></div></div></div>");
            tmp = tmp.replace(/\$from\$/gi,C0102.replace("{0}",GetLanguageLabel("jselCountry",obj.Nationality)));
                if(obj.Gender=="1")
                {
                    tmp = tmp.replace(/\$Gender\$/gi,gMale+",");
                }
                else if(obj.Gender=="0")
                {
                    tmp = tmp.replace(/\$Gender\$/gi,gFemale+",");
                }
                else
                {
                    tmp = tmp.replace(/\$Gender\$/gi,"");
                }
                if(obj.Online == true)
                {
                    tmp = tmp.replace(/\$Online\$/gi,gOnlineN);
                }
                else
                {
                    var arr1 = gDateFormat.split(":");
                    var arr2 = obj.DiffLastUpdate.split(":");
                    if(arr2[0]>0)
                    {
                        tmp = tmp.replace(/\$Online\$/gi,gStrDate.replace("{0}",arr2[0]).replace("{1}",arr1[0]));
                    }
                    else if(arr2[1]>0)
                    {
                        tmp = tmp.replace(/\$Online\$/gi,gStrDate.replace("{0}",arr2[1]).replace("{1}",arr1[1]));
                    }
                    else if(arr2[2]>0)
                    {
                        tmp = tmp.replace(/\$Online\$/gi,gStrDate.replace("{0}",arr2[2]).replace("{1}",arr1[2]));
                    }
                    else if(arr2[3]>0)
                    {
                        tmp = tmp.replace(/\$Online\$/gi,gStrDate.replace("{0}",arr2[3]).replace("{1}",arr1[3]));
                    }
                    else if(arr2[4]>0)
                    {
                        tmp = tmp.replace(/\$Online\$/gi,gStrDate.replace("{0}",arr2[4]).replace("{1}",arr1[4]));
                    }
                    else if(arr2[5]>0)
                    {
                        tmp = tmp.replace(/\$Online\$/gi,gStrDate.replace("{0}",arr2[5]).replace("{1}",arr1[5]));
                    }
                    else
                    {
                        tmp = tmp.replace(/\$Online\$/gi,"");
                    }                    
                }
                switch(ShowUserType)
                {
                    case 1:
                    var Optype=IsAffirm?("<a href=\"#\" onclick=\"javascript:('"+Memberno+"'=='')?window.location.href='/user/login.htm?ReturnUrl='+window.location.href:$Getmail$('"+obj.MemberNo+"')\">"+gSendM+"</a><br /> <img src=\"/Images/icon_chat.gif\" align=\"absmiddle\" /> <a href=\"javascript:void(0);\" onclick=\"javascript:('"+Memberno+"'=='')?window.location.href='/user/login.htm?ReturnUrl='+top.location.href:up_launchWM( '"+Memberno.toString().trimStart('T').trimStart('0')+"', '"+obj.MemberNo.toString().trimStart('T').trimStart('0')+"' ); return false;\">"+gChatN+"</a>"):("<a href=\"#\" onclick=\"NotAffirm()\">"+gSendM+"</a><br /> <img src=\"/Images/icon_chat.gif\" align=\"absmiddle\" /> <a href=\"javascript:void(0);\" onclick=\"NotAffirm()\">"+gChatN+"</a>");
                        tmp = tmp.replace(/\$OperateType\$/gi,"<img src=\"/Images/icon_common_mailbox.gif\" align=\"absmiddle\" />"+Optype+"<br /> <img src=\"/Images/icon_cancel.gif\" align=\"absmiddle\" /> <a href=\"#\" onclick=\"OpContacts('"+obj.MemberNo+"',1)\">"+gRemove+"</a>");
                        break;
                    case 2:                        
                        tmp = tmp.replace(/\$OperateType\$/gi,"<img src=\"/Images/icon_accept.gif\" align=\"absmiddle\" /> <a href=\"#\" onclick=\"OpContacts('"+obj.MemberNo+"',3)\">"+gAccept+"</a><br /> <img src=\"/Images/icon_cancel.gif\" align=\"absmiddle\" /> <a href=\"#\" onclick=\"OpContacts('"+obj.MemberNo+"',1)\"> "+gDecline+"</a>");                        
                        break;
                    case 3:                        
                        tmp = tmp.replace(/\$OperateType\$/gi,"<img src=\"/Images/icon_cancel.gif\" align=\"absmiddle\" /> <a href=\"#\" onclick=\"OpContacts('"+obj.MemberNo+"',1)\"> "+gCancel+"</a>");
                        break;
                }
                listBuilder.append(tmp);
            }            
            var sTemp = listBuilder.toString();
            domDiv.innerHTML = sTemp;     
        }
    }
}
//替换标题
function RendTitle()
{	
    $get("FriendCount").innerHTML=(FriendCount<0 ? 0 : FriendCount);
    $get("ReceiveCount").innerHTML=(ReceiveCount<0 ? 0 : ReceiveCount);
    $get("SendCount").innerHTML=(SendCount<0 ? 0 : SendCount);
}
//操作联系人（朋友号； 1：删除联系人、3：同意加为好友）
function OpContacts(fMemberno,type)
{
    showProgressBar(false,true);
    $("$divIput$").style.display = "none";
    var title = "";
    var body="";
    var obj = {}    
    switch(type)
    {
        case 1:
            title = GP066;
            body = "<p><strong>"+C1008+"</strong></p><br/><div class='Popup_button'><input type='button' value='"+C0069+"' id='addOkButton' class='button' onclick=\"opWebService('"+fMemberno+"',1)\" />&nbsp;&nbsp;<input type='button' value='"+gCancel+"' id='addCancelButton' class='buttong' onclick='webFailure()'/></div>";//"<p><strong>"+C1008+"</strong></p>";
            break;        
        case 3:
            title = C1008;
            body="<div class='Popup_button'><input type='button' value='"+C0069+"' id='addOkButton' class='button' onclick=\"opWebService('"+fMemberno+"',3)\" />&nbsp;&nbsp;<input type='button' value='"+gCancel+"' id='addCancelButton' class='buttong' onclick='webFailure()'/></div>";
            break;    
    }    
    $ShowMessageBox$(title,body,obj,webFailure,200);    
}
//执行相关操作
function opWebService(fMemberno,tp)
{    
    switch(tp)
    {
        case 1:       
            WebServices.User.Contacts.DeleContacts(Memberno,fMemberno,onsuccOP,webFailure,1);
            break;        
        case 3:        
            WebServices.User.Contacts.AcceptFriend(Memberno,fMemberno,onsuccOP,webFailure,3);
            break;
    }  
}
//调用webService方法失败
function webFailure()
{
    $EndMessageBox$();
}
function onsuccOP(result,type)
{  
    $EndMessageBox$();
    var friends=0;
    if(result.State) 
    {   
        if(type)
        {
            switch(type)
            {
                case 1:
                    if(gLastCount==1) gPageIndex = gPageIndex -1;
                    if(gPageIndex<1) gPageIndex = 1; 
                    switch(ShowUserType)
                    {                    
                        case 1:
                            FriendCount--;                               
                            if(FriendCount==0)
                            {
                                ShowUserType=0;                            
                            }
                            break;
                        case 2:
                            ReceiveCount--;
                            break;
                        case 3:
                            SendCount--;
                            break;
                    }
                    break;
                case 2:
                    SendCount++;
                    break;
                case 3:
					FriendCount==0?friends=1:friends=0;
                    FriendCount++;
                    ReceiveCount--;                    
                    break;
            }
            RendTitle();
        }     
        InitDataMembers(ShowUserType,gPageIndex);
        friends==1?ShowUserType=1:friends=0;        
    }
}
function openDiv1(url,title,clstxt,width,height)
{
    if(!Memberno||Memberno=="")
    {
        top.location = "/user/login.htm?IsShow=1&ReturnUrl="+top.location.href;
        return;
    }
    openDiv(url,title,clstxt,width,height);
}
//即时聊天
function up_launchWM(userID,destinationUserID,destinationName)
{
    window.open( "/webchat/wm_ads.aspx?strDestinationUserID=" + destinationUserID, "WMWindow_" + up_replaceAlpha(userID) + "_" + up_replaceAlpha(destinationUserID), "width=500,height=600,toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=1" );
}
function up_replaceAlpha(strIn)
{
    var strOut = "";
    for( var i = 0 ; i < strIn.length ; i++ )
    {
        var cChar = strIn.charAt(i);
        if( ( cChar >= 'A' && cChar <= 'Z' )
            || ( cChar >= 'a' && cChar <= 'z' )
            || ( cChar >= '0' && cChar <= '9' ) )
        {
            strOut += cChar;
        }
        else
        {
            strOut += "_";
        }
    }
    return strOut;
}
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();